package com.gitee.mazhenggg.mall.account.mybatis.impl;

import com.gitee.mazhenggg.mall.account.domain.repository.AccountRepository;

import com.gitee.mazhenggg.mall.account.domain.type.Money;
import com.gitee.mazhenggg.mall.account.domain.type.UserId;
import com.gitee.mazhenggg.mall.account.mybatis.mapper.AccountDOMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class AccountRepositoryImpl implements AccountRepository {

    @Autowired
    AccountDOMapper accountDOMapper;
    @Override
    public Money getBalanceByUserId(UserId userId) {
        return new Money(accountDOMapper.getAvailableByUserId(userId.getId()));
    }

    @Override
    public void reduceAccountByUserId(UserId userId, Money amount) {
        accountDOMapper.reduceAccountByUserId(userId.getId(),amount.getValue());
    }
}